SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[SP_TTSUBR_FINA_Q02]
/*--------------------------------------------------------*/        
/*---Empresa               OFISIS S.A.                  --*/        
/*---Cliente               CIA Hitepima					--*/        
/*---Sistema               Tesoreria					--*/        
/*---M«dulo                Empresa						--*/        
/*---Programa              FLUJO DE CAJA MENSUAL		--*/        
/*---Script                SP_TTSUBR_FINA_Q02.sql		--*/        
/*---Nombre SP             SP_TTSUBR_FINA_Q02			--*/        
/*---Desarrollado por      Carlos Marquez				--*/        
/*---Fecha Creaci«n        08/04/2006					--*/        
/*---Base Datos            SQL SERVER					--*/        
/*---Versi«n               2000							--*/        
/*---Invoca a SP          								--*/        
/*-------------------------------------------------------*/        
/*-------------------------------------------------------*/        
/*---Modificado 1 por     : Carlos Marquez Escobar     --*/        
/*---Fecha Modificaci«n   : 08/04/2006			       --*/         
/*---Detalle Modificaci«n : Adicionaron Campos		   --*/        
/*-------------------------------------------------------*/        
/*-------------------------------------------------------*/        
/*--- Drop Proc SP_TTSUBR_FINA_Q02      --*/        
/*--- Grant Execute on SP_TTSUBR_FINA_Q02 to public  --*/         
/*--- SP_TTSUBR_FINA_Q02 '01', 2006, 4,  '2006-04-01', 'P', 'DOL' --*/        
/*--------------------------------------------------------*/        
@ISCO_EMPR		TD_VC_002,
@INNU_ANNO		TD_IN_001,
@INNU_MESE		TD_IN_001,
@IDFE_PROY_EJEC	TD_DT_001,
@ISTI_REPO		TD_VC_001,
@ISCO_MONE		TD_VC_003

As        

Select 
		t1.CO_ARUB, t1.CO_RUBR, t1.CO_SUBR,
		Max(t1.DE_SUBR),
		Sum(PatIndex(t0.NU_MESE_PROY,  '1') * t0.IM_DIGI) ENERO,
		Sum(PatIndex(t0.NU_MESE_PROY,  '2') * t0.IM_DIGI) FEBRERO,
		Sum(PatIndex(t0.NU_MESE_PROY,  '3') * t0.IM_DIGI) MARZO,
		Sum(PatIndex(t0.NU_MESE_PROY,  '4') * t0.IM_DIGI) ABRIL,
		Sum(PatIndex(t0.NU_MESE_PROY,  '5') * t0.IM_DIGI) MAYO,
		Sum(PatIndex(t0.NU_MESE_PROY,  '6') * t0.IM_DIGI) JUNIO,
		Sum(PatIndex(t0.NU_MESE_PROY,  '7') * t0.IM_DIGI) JULIO,
		Sum(PatIndex(t0.NU_MESE_PROY,  '8') * t0.IM_DIGI) AGOSTO,
		Sum(PatIndex(t0.NU_MESE_PROY,  '9') * t0.IM_DIGI) SETIEMBRE,
		Sum(PatIndex(t0.NU_MESE_PROY, '10') * t0.IM_DIGI) OCTUBRE,
		Sum(PatIndex(t0.NU_MESE_PROY, '11') * t0.IM_DIGI) NOVIEMBRE,
		Sum(PatIndex(t0.NU_MESE_PROY, '12') * t0.IM_DIGI) DICIEMBRE
From	TTSUBR_FINA t1, TTRUBR_FINA t2, TTARUB_FINA t3,
		TWSUBR_FINA t0
Where   	t1.CO_EMPR = @ISCO_EMPR
	And 	t1.CO_EMPR = t2.CO_EMPR
	And 	t1.CO_ARUB = t2.CO_ARUB
	And 	t1.CO_RUBR = t2.CO_RUBR
	And 	t2.CO_EMPR = t3.CO_EMPR
	And 	t2.CO_ARUB = t3.CO_ARUB

	And 	t1.CO_EMPR = t0.CO_EMPR
	And 	t1.CO_SUBR = t0.CO_SUBR
	And 	t0.CO_SUBR = t0.CO_SUBR
	And 	t0.NU_ANNO = @INNU_ANNO
	And 	t0.NU_MESE = @INNU_MESE
	And 	t0.FE_PROY_EJEC = @IDFE_PROY_EJEC
	And 	t0.TI_REPO = @ISTI_REPO
	And 	t0.CO_MONE = @ISCO_MONE

Group By	t1.CO_ARUB, t1.CO_RUBR, t1.CO_SUBR
Order By 	t1.CO_ARUB, t1.CO_RUBR, t1.CO_SUBR

        
RETURN        
/********************************* FIN ***********************************/


GO
